﻿using MediatR;
using SlaughterItem.Common.Domains.UPCTable;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.GetUPCData
{
    //显示商品代号表数据
    public class ShowUPCDataHandler : IRequestHandler<ShowUPCDataCommand, Result>
    {
        public ShowUPCDataHandler(IBaseRepositoryGet<UPCData> uPCDataRepositoryGet)
        {
            UPCDataRepositoryGet = uPCDataRepositoryGet;
        }

        public IBaseRepositoryGet<UPCData> UPCDataRepositoryGet { get; set; }
        public async Task<Result> Handle(ShowUPCDataCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CommonErrorCode.Search};
            var list = UPCDataRepositoryGet.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;    
            }
        }
    }
}
